


<!DOCTYPE html>
<html id="htmlId">
<head>
  <title>Coverage Report > Game</title>
  <style type="text/css">
    @import "../../css/coverage.css";
    @import "../../css/idea.min.css";
  </style>
  <script type="text/javascript" src="../../js/highlight.min.js"></script>
  <script type="text/javascript" src="../../js/highlightjs-line-numbers.min.js"></script>
</head>

<body>
<div class="content">
<div class="breadCrumbs">
Current scope:     <a href="../../index.html">all classes</a>
    <span class="separator">|</span>
    <a href="../index.html">nl.tudelft.jpacman.game</a>
</div>

<h1>Coverage Summary for Class: Game (nl.tudelft.jpacman.game)</h1>

<table class="coverageStats">
<tr>
  <th class="name">Class</th>
<th class="coverageStat 
">
  Class, %
</th>
<th class="coverageStat 
">
  Method, %
</th>
<th class="coverageStat 
">
  Line, %
</th>
</tr>
<tr>
  <td class="name">Game</td>
<td class="coverageStat">
  <span class="percent">
    100%
  </span>
  <span class="absValue">
    (1/1)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    71.4%
  </span>
  <span class="absValue">
    (5/7)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    80%
  </span>
  <span class="absValue">
    (24/30)
  </span>
</td>
</tr>

</table>

<br/>
<br/>


<pre>
<code class="sourceCode" id="sourceCode">&nbsp;package nl.tudelft.jpacman.game;
&nbsp;
&nbsp;import java.util.List;
&nbsp;
&nbsp;import nl.tudelft.jpacman.board.Direction;
&nbsp;import nl.tudelft.jpacman.level.Level;
&nbsp;import nl.tudelft.jpacman.level.Level.LevelObserver;
&nbsp;import nl.tudelft.jpacman.level.Player;
&nbsp;import nl.tudelft.jpacman.points.PointCalculator;
&nbsp;
&nbsp;/**
&nbsp; * A basic implementation of a Pac-Man game.
&nbsp; *
&nbsp; * @author Jeroen Roosen 
&nbsp; */
&nbsp;public abstract class Game implements LevelObserver {
&nbsp;
&nbsp;    /**
&nbsp;     * &lt;code&gt;true&lt;/code&gt; if the game is in progress.
&nbsp;     */
&nbsp;    private boolean inProgress;
&nbsp;
&nbsp;    /**
&nbsp;     * Object that locks the start and stop methods.
&nbsp;     */
<b class="fc">&nbsp;    private final Object progressLock = new Object();</b>
&nbsp;
&nbsp;    /**
&nbsp;     * The algorithm used to calculate the points that
&nbsp;     * they player gets whenever some action happens.
&nbsp;     */
&nbsp;    private PointCalculator pointCalculator;
&nbsp;
&nbsp;    /**
&nbsp;     * Creates a new game.
&nbsp;     *
&nbsp;     * @param pointCalculator
&nbsp;     *             The way to calculate points upon collisions.
&nbsp;     */
<b class="fc">&nbsp;    protected Game(PointCalculator pointCalculator) {</b>
<b class="fc">&nbsp;        this.pointCalculator = pointCalculator;</b>
<b class="fc">&nbsp;        inProgress = false;</b>
<b class="fc">&nbsp;    }</b>
&nbsp;
&nbsp;    /**
&nbsp;     * Starts or resumes the game.
&nbsp;     */
&nbsp;    public void start() {
<b class="fc">&nbsp;        synchronized (progressLock) {</b>
<b class="fc">&nbsp;            if (isInProgress()) {</b>
<b class="nc">&nbsp;                return;</b>
&nbsp;            }
<b class="fc">&nbsp;            if (getLevel().isAnyPlayerAlive() &amp;&amp; getLevel().remainingPellets() &gt; 0) {</b>
<b class="fc">&nbsp;                inProgress = true;</b>
<b class="fc">&nbsp;                getLevel().addObserver(this);</b>
<b class="fc">&nbsp;                getLevel().start();</b>
&nbsp;            }
<b class="fc">&nbsp;        }</b>
<b class="fc">&nbsp;    }</b>
&nbsp;
&nbsp;    /**
&nbsp;     * Pauses the game.
&nbsp;     */
&nbsp;    public void stop() {
<b class="fc">&nbsp;        synchronized (progressLock) {</b>
<b class="fc">&nbsp;            if (!isInProgress()) {</b>
<b class="nc">&nbsp;                return;</b>
&nbsp;            }
<b class="fc">&nbsp;            inProgress = false;</b>
<b class="fc">&nbsp;            getLevel().stop();</b>
<b class="fc">&nbsp;        }</b>
<b class="fc">&nbsp;    }</b>
&nbsp;
&nbsp;    /**
&nbsp;     * @return &lt;code&gt;true&lt;/code&gt; iff the game is started and in progress.
&nbsp;     */
&nbsp;    public boolean isInProgress() {
<b class="fc">&nbsp;        return inProgress;</b>
&nbsp;    }
&nbsp;
&nbsp;    /**
&nbsp;     * @return An immutable list of the participants of this game.
&nbsp;     */
&nbsp;    public abstract List&lt;Player&gt; getPlayers();
&nbsp;
&nbsp;    /**
&nbsp;     * @return The level currently being played.
&nbsp;     */
&nbsp;    public abstract Level getLevel();
&nbsp;
&nbsp;    /**
&nbsp;     * Moves the specified player one square in the given direction.
&nbsp;     *
&nbsp;     * @param player
&nbsp;     *            The player to move.
&nbsp;     * @param direction
&nbsp;     *            The direction to move in.
&nbsp;     */
&nbsp;    public void move(Player player, Direction direction) {
<b class="fc">&nbsp;        if (isInProgress()) {</b>
&nbsp;            // execute player move.
<b class="fc">&nbsp;            getLevel().move(player, direction);</b>
<b class="fc">&nbsp;            pointCalculator.pacmanMoved(player, direction);</b>
&nbsp;        }
<b class="fc">&nbsp;    }</b>
&nbsp;
&nbsp;    @Override
&nbsp;    public void levelWon() {
<b class="nc">&nbsp;        stop();</b>
<b class="nc">&nbsp;    }</b>
&nbsp;
&nbsp;    @Override
&nbsp;    public void levelLost() {
<b class="nc">&nbsp;        stop();</b>
<b class="nc">&nbsp;    }</b>
&nbsp;}
</code>
</pre>
</div>

<script type="text/javascript">
(function() {
    var msie = false, msie9 = false;
    /*@cc_on
      msie = true;
      @if (@_jscript_version >= 9)
        msie9 = true;
      @end
    @*/

    if (!msie || msie && msie9) {
      hljs.highlightAll()
      hljs.initLineNumbersOnLoad();
    }
})();
</script>

<div class="footer">
    
    <div style="float:right;">generated on 2023-04-11 19:39</div>
</div>
</body>
</html>
